<?php
namespace src\logic;
use \classlib\core as C;
class ltags {
	/**
	 * 重建标签关系
	 * @param int $sid
	 * @param array $tagids
	 */
	public static function build($sid, $tagids) {
		$orm = C\model::load('pro.pl.tags');
		$orm->get_orm()->where('studioid', $sid)->delete();
		foreach ($tagids as $tagid) {//建立标签关系表
			if (!is_numeric($tagid)) {
				continue;
			}
			$fields = array('tagid'=>$tagid, 'studioid'=>$sid);
			$orm->get_orm()->insert($fields, true);
		}
		$orm->set_ver();
		return implode(',', $tagids);
	}
	
	/**
	 * 获取标签的名称信息
	 * @param unknown $tagids
	 * @param string $lng
	 * @return string
	 */
	public static function stag_name($tagids, $lng='en') {
		$where = array(array('id', $tagids, \classlib\orm::OP_IN));
		$names = C\model::load('pro.inc.tags')->get_column(0, -1, $where, 'name');
		return implode(',', $names);
	}
	
	/**
	 * 获取系统配置的标签信息列表
	 * @param string $lng
	 * @return array $list
	 */
	public static function systags($lng='en') {
		$where = array('isshow'=>1, 'status'=>1);
		$field = 'id, name, icon, thumb as wicon';
		$list  = C\model::load('pro.inc.tags')
			->get_list(0, -1, $where, $field, 'rank', \classlib\orm::DESC);
		return $list;
	}
}